package com.mryang.hds.controller;

import com.mryang.hds.entity.Notify;
import com.mryang.hds.service.INotifyService;
import com.mryang.hds.utils.JWTUtil;
import com.mryang.hds.utils.ResultJson;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;
import sun.security.jgss.HttpCaller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author Genius
 * @version 1.0.0
 * @ClassName NotifyController.java
 * @Description TODO
 * @createTime 2023年03月22日 21:04:00
 */

@RestController
@RequestMapping("/api/notify")
public class NotifyController {


    @Resource
    INotifyService iNotifyService;

    // 获取指定用户（即被通知用户）的消息列表
    @GetMapping("/getmsgbyuid")
    public ResultJson getMesByUserId(HttpServletRequest httpServletRequest){

        Integer userId = JWTUtil.getTokenInfoIndex(httpServletRequest.getHeader("token"));

        List<Notify> mesByUserId = iNotifyService.getMesByUserId(userId);

        return ResultJson.success(mesByUserId,"消息查询成功");
    }

    @GetMapping("/getnotifybyuid")
    public ResultJson<Object> getNotifyByUID(HttpServletRequest httpServletRequest) {

        Integer uid = JWTUtil.getTokenInfoIndex(httpServletRequest.getHeader("token"));
        List<Notify> mesByUserId = iNotifyService.getNotifyByUID(uid);

        return ResultJson.success(mesByUserId,"消息查询成功");
    }

    @PutMapping("/editnotifylook/{nid}")
    public ResultJson<Object> getNotifyByUID(@PathVariable Integer nid, HttpServletRequest httpServletRequest) {

        iNotifyService.editLookById(nid);

        return ResultJson.success("修改成功");
    }





}
